package com.firewolf.springcloud.config;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

/**
 * 作者：刘兴
 * 时间:19/2/15
 **/
@Configuration
public class HystrixConfig {

    //添加一个servlet请求，用于处理hystrix请求

    //SSM拦截器

    @Bean
    public ServletRegistrationBean hystrixServlet(){
        HystrixMetricsStreamServlet hystrixMetricsStreamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(hystrixMetricsStreamServlet);
        servletRegistrationBean.setLoadOnStartup(0);
        servletRegistrationBean.setUrlMappings(Arrays.asList("/hystrix.stream")); //servlet处理的路径
        servletRegistrationBean.setName("HystrixMetricsStreamServlet"); //servlet的名字
        return  servletRegistrationBean;
    }
}
